<?php
/**
 * Created by PhpStorm.
 * User: lihao
 * Date: 2017/7/24
 * Time: 下午4:14
 */

class Project_model extends CI_Model {
    public function __construct() {
        parent::__construct();
    }

//    创建文章
    public function create($data) {
        $this->db->insert('project',$data);
        $result = $this->db->insert_id();
        //最新数字 id
        return $result;
    }

//    更新文章
    public function update($proid, $data) {
//        $this->db->where('proid', $proid);
//        $re = $this->db->update('project', $data);
        $this->db->set($data);
        $this->db->where('proid', $proid);
        $re = $this->db->update('project');
        return $re;
    }

//    删除文章
    public function delePro($proid) {
        $this->db->where('proid', $proid);
        $re = $this->db->delete('project');
        return $re;
    }

//    获取文章
    public function getlist($where, $limit, $offset) {
        $this->db->select('*');
        $this->db->from('project');
        //
        $this->db->join('protype', 'protype.typeid = project.typeid', 'left');
        if ($where != null) {
            $this->db->where($where);
        }
        if ($limit != null) {
            $this->db->limit($limit, $offset);
        }
        //
        $this->db->order_by('proid', 'DESC');
        $re = $this->db->get()->result_array();
        return $re;
    }

//    获取文章分类
    public function protype() {
        $re = $this->db->get('protype')->result_array();
        return $re;
    }
}